#ifndef __KERNEL_DEVICE_H_
#define __KERNEL_DEVICE_H_

#include "typedef.h"
#include "queueapi.h"
#include "astraldef.h"
#include "_2device.h"

#define COMN_DEV_DEFINE      \
    char name[10];           \
    u32 type;                \
    int irq;                 \
    address base;            \
    struct QueueNode dnode;  \
    boolean (*open)(object); \
    boolean (*close)(object);

#define CHAR_DEV_DEFINE          \
    COMN_DEV_DEFINE              \
    int (*write)(address, char); \
    char (*read)(address);

typedef struct Device
{
    COMN_DEV_DEFINE
} *Device;

typedef struct CharDevice
{
    CHAR_DEV_DEFINE
} *CharDevice;


/**
 * @brief Device->CharDevice->SerialDevice
 * @note extends from base class
 */
typedef struct SerialDevice
{
    CHAR_DEV_DEFINE
    void (*ack_rx_int)(address base);
} *SerialDevice;


typedef struct DInfo {
    u32 type;
    address base;
    int irq;
    const char * name;
    #define SERIAL 0x123
} *DInfo;


object find_device_via_intid(int id);
boolean open_serial_dev(CharDevice cd);
boolean binding_char_dev(DInfo info, Device dev);
boolean binding_serial_dev(DInfo info, Device dev);
AstralDevInfo get_static_devinfo(AstralDevInfo curr);

#endif//__KERNEL_DEVICE_H_